package com.sskj.trafficcontrol.util;

import com.alibaba.fastjson.JSONObject;
import com.sskj.trafficcontrol.model.vo.LocalcarBean;
import com.sskj.trafficcontrol.model.vo.LuBangXianingInfoVO;

import java.util.HashMap;
import java.util.Map;

/**
 * @author : zhao kuo
 * @date : 2019/2/15 09:22
 * @description :
 */
public class LuBangXianxingUtil {

    private final static String API_KEY = "d9194c30-1268-0137-339b-0242c0a80006";

    private final static String GET_CITY_LIST_URL = "http://www.loopon.cn/api/v1/trafficlimit/number/getCityList";

    private final static String GET_CITY_XIANXING_INFO_URL = "http://www.loopon.cn/api/v1/trafficlimit/number/getCityLimit";


    public static LuBangXianingInfoVO getCityXianxingInfo(String cityCode){

        String result = null;
        String url = GET_CITY_XIANXING_INFO_URL;//请求接口地址
        Map params = new HashMap();//请求参数
        params.put("apikey", API_KEY);//应用APPKEY(应用详细页查询)
        params.put("city", cityCode);//城市代码，在城市列表接口获取

        try {
            result = TrafficControlUtil.net(url, params, "GET");
            LuBangXianingInfoVO object = JSONObject.parseObject(result,LuBangXianingInfoVO.class);

            if (object.getRspcode() == 20000) {
//                return object.get("localcar").toString();
                return object;
            } else {
//                return object.get("rspcode").toString();
                return null;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return  null;
        }

    }

    public static void main(String[] args) {
        LuBangXianingInfoVO xianxing = getCityXianxingInfo("110000");
        LuBangXianingInfoVO.LocalcarBean localcarBean = xianxing.getLocalcar().get(0);
        System.out.println(localcarBean.getArea());
        System.out.println(localcarBean.getNumber());
    }

}
